Public Class OwnDiagnoseHistory

    Protected _year As String
    Protected _Police As New Police()
    Protected _cbc As Boolean
    Protected _ua As Boolean
    Protected _chem As Boolean
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property Police() As Police
        Get
            Return _Police
        End Get
        Set(ByVal value As Police)
            _Police = value
        End Set
    End Property

    Public Property cbc() As Boolean
        Get
            Return _cbc
        End Get
        Set(ByVal value As Boolean)
            _cbc = value
        End Set
    End Property

    Public Property ua() As Boolean
        Get
            Return _ua
        End Get
        Set(ByVal value As Boolean)
            _ua = value
        End Set
    End Property

    Public Property chem() As Boolean
        Get
            Return _chem
        End Get
        Set(ByVal value As Boolean)
            _chem = value
        End Set
    End Property

    Public Function getOwnDiagnoseHistoryYear() As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OwnDiagnoseHistoryYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OwnDiagnoseHistoryYear")

        Return objDs
    End Function

    Protected Function getsOwnDiagnoseHistoryYear() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OwnDiagnoseHistoryYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OwnDiagnoseHistoryYear")

        For Each objDr As System.Data.DataRow In objDs.Tables("OwnDiagnoseHistoryYear").Rows
            Dim obj As OwnDiagnoseHistory = New OwnDiagnoseHistory()
            obj.year = objDr.Item("year")
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function getOwnDiagnoseHistory(ByVal pYear As String, ByVal pOrganizationID As String) As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OwnDiagnoseHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", pOrganizationID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", pYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OwnDiagnoseHistory")

        Return objDs
    End Function

    Protected Function getsOwnDiagnoseHistory(ByVal pYear As String, ByVal pOrganizationID As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OwnDiagnoseHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", pOrganizationID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", pYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OwnDiagnoseHistory")

        For Each objDr As System.Data.DataRow In objDs.Tables("OwnDiagnoseHistory").Rows
            Dim obj As OwnDiagnoseHistory = New OwnDiagnoseHistory()
            obj.year = pYear
            obj.Police.citizen_id = objDr.Item("citizen_id")
            obj.Police.prename.prename_short_tha = objDr.Item("prename_short_tha")
            obj.Police.name = objDr.Item("name_tha")
            obj.Police.surname = objDr.Item("surname_tha")
            obj.cbc = objDr.Item("cbc")
            obj.ua = objDr.Item("ua")
            obj.chem = objDr.Item("chem")
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function insertOwnDiagnoseHistory() As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_OwnDiagnoseHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", year)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", Police.citizen_id)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCBC", cbc)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inUA", ua)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inChem", chem)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _year = _Data(_DataCurrent).year
            _Police.citizen_id = _Data(_DataCurrent).Police.citizen_id
            _Police.prename.prename_short_tha = _Data(_DataCurrent).Police.prename.prename_short_tha
            _Police.name = _Data(_DataCurrent).Police.name
            _Police.surname = _Data(_DataCurrent).Police.surname
            _cbc = _Data(_DataCurrent).cbc
            _ua = _Data(_DataCurrent).ua
            _chem = _Data(_DataCurrent).chem
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub loadOwnDiagnoseHistoryYear()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsOwnDiagnoseHistoryYear()
    End Sub

    Public Sub loadOwnDiagnoseHistory(ByVal pYear As String, ByVal pOrganizationID As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsOwnDiagnoseHistory(pYear, pOrganizationID)
    End Sub

End Class
